package com.bm.Result;

import lombok.Builder;
import lombok.Data;
import lombok.Setter;

/**
 * @author 86134
 * @version 1.0
 * @description 通用结果放回类
 * @date 2024/1/22 20:31
 */
@Builder
@Data
@Setter
public class Result {

    //表示返回的结果码，比如200成功，500失败
    private int code;

    //表示返回的结果信息，比如 用户登录状态失效了，请求参数格式有误.......
    private String msg;

    //表示返回的结果数据，数据可能是一个对象，也可以是一个List集合.....
    private Object data;

    public static Result OK(){
        return Result.builder().code(CodeEnum.OK.getCode()).
                msg(CodeEnum.OK.getMsg()).
                build();
    }

    public static Result OK(int code , String msg){
        return Result.builder().code(code).
                msg(msg).
                build();
    }

    public static Result OK(Object data){
        return Result.builder().code(CodeEnum.OK.getCode()).
                msg(CodeEnum.OK.getMsg()).
                data(data).
                build();
    }

    public static Result OK(CodeEnum codeEnum){
        return Result.builder().code(codeEnum.OK.getCode()).
                msg(codeEnum.OK.getMsg()).
                build();
    }

    public static Result FAIL(){
        return Result.builder()
                .code(CodeEnum.FAIL.getCode())
                .msg(CodeEnum.FAIL.getMsg())
                .build();
    }

    public static Result FAIL(String msg){
        return Result.builder()
                .code(CodeEnum.FAIL.getCode())
                .msg(msg)
                .build();
    }

    public static Result FAIL(CodeEnum codeEnum){
        return Result.builder()
                .code(codeEnum.getCode())
                .msg(codeEnum.getMsg())
                .build();
    }


}
